package me.barcodescanner.zbar;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;

import me.barcodescanner.util.ZBarHelper;

public class ScannerActivity extends Activity implements ZBarScannerView.ResultHandler, View.OnClickListener{
    private ZBarScannerView mScannerView;

    @Override
    public void onCreate(Bundle state) {
        super.onCreate(state);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_scanner);
        findViewById(R.id.tv_back).setOnClickListener(this);
        findViewById(R.id.tv_sel_photo).setOnClickListener(this);

        mScannerView = findViewById(R.id.scanner_view);

        int type = getIntent().getIntExtra("type", 0);
        if (type == ZBarHelper.CODE_TYPE_ONE_D) {
            mScannerView.setFormats(ZBarcodeFormat.ONE_D_CODE_FORMATS);
        }
        if (type == ZBarHelper.CODE_TYPE_QR_CODE) {
            mScannerView.setFormats(ZBarcodeFormat.QR_CODE_FORMATS);
        }

    }

    @Override
    public void onResume() {
        super.onResume();
        mScannerView.setResultHandler(this);
        mScannerView.startScan();

    }

    @Override
    public void onPause() {
        super.onPause();
        mScannerView.stopScan();
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tv_back) {
            finish();
        }
        if (id == R.id.tv_sel_photo) {

        }
    }

    @Override
    public void handleResult(Result rawResult) {
        finish();
    }

}
